
import 'package:flutter/material.dart';

class RichTextTest extends StatefulWidget {

  @override
  _RichTextTestState createState() => _RichTextTestState();
}

class _RichTextTestState extends State<RichTextTest> {

  int size = 50;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('RichTxt'),
        actions: <Widget>[
          IconButton(
            onPressed: (){
              setState(() {
                size += 50;
              });
            },
            icon : Icon(Icons.add_circle_outline)
          ),
          IconButton(
            onPressed: (){
              setState(() {
                size -= 50;
              });
            },
            icon : Icon(Icons.remove_circle_outline)
          ),
        ],
      ),
      body: Container(
        margin: EdgeInsets.all(10),
        child: Builder(builder: (context){
          return Center(
            child: Text.rich(TextSpan(
              children: <InlineSpan>[
                TextSpan(text: 'Flutter is'),
                WidgetSpan(
                  child: SizedBox(
                    width: 120,
                    height: 50,
                    child: Card(
                      color: Colors.blue,
                      child: Center(child: Text('Hello world!'),),),
                  )
                ),
                WidgetSpan(
                  child: SizedBox(
                    width: size.toDouble() > 0.0 ? size.toDouble() : 0.0,
                    height: size.toDouble() > 0.0 ? size.toDouble() : 0.0,
                    child: Image.asset('images/itachi.jpg', fit: BoxFit.cover,),
                  )
                ),
                TextSpan(text: 'the best!')
              ]
            )),
          );
        },),
      ),
    );
  }
}
